
package puziran.party.controllers;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.serfj.RestController;
import net.sf.serfj.annotations.POST;

import org.apache.log4j.Logger;

import puziran.party.services.UserOperationService;
import puziran.party.util.JSONHelper;
import puziran.sofa.serializer.JsonGenerateUtil;
import puziran.sofa.serializer.JsonResponse;
import puziran.sofa.util.SerfjUtil;
import puziran.sofa.util.SofaSpringContext;
/**
 * 
 * 类名: Useroperationc <br/>
 * 功能: TODO 会员操作类，所调用实现类有事务. <br/>
 *       TODO 例如操作多表时候.Service需要调用多个dao <br/>
 × 时间: 2014年10月4日 下午6:36:48 <br/>
 * @author  changjiang.yang
 * @version  v0.0.1
 * @since JDK 1.7
 */
public class Useroperationc extends RestController{
	public static Logger logger = Logger.getLogger(Useroperationc.class);
	
	/**
	 * 
	 * initUser:(会员注册使用). <br/>
	 * TODO(会员注册).<br/>
	 * 时间:2014年10月4日下午6:39:43
	 * 作者:changjiang.yang
	 * @return json
	 * @since JDK 1.7
	 */
	@POST
	public String initUser(){
		Map<String, String> map = SerfjUtil.removeFilter(this.getParams());
		UserOperationService userOperationService = (UserOperationService) SofaSpringContext
				.getBean("userOperationService"); // 调用接口(实现类)
		String msgJson = userOperationService.initUser(map);
		if("sorry".equals(msgJson)){
			msgJson = JsonGenerateUtil.getCommonJson("error","请检查邮箱或用户名是否验证唯一","","");
		}else{
			Map<String,String> msgJsonMap = JSONHelper.JSON2MapStr(msgJson);
			msgJson = JsonGenerateUtil.getCommonJson("success","初始化成功","",msgJsonMap);
		}
		HttpServletResponse response = this.getResponseHelper().getResponse();
		return new JsonResponse().responseJson(response, msgJson); // 返回 Json格式:
	}
	/**
	 * 登陆验证
	 * @param username password operator
	 * @return
	 */
	@POST
	public String vilidateUser(){
		Map<String, String> map = SerfjUtil.removeFilter(this.getParams());
		UserOperationService userOperationService = (UserOperationService) SofaSpringContext
				.getBean("userOperationService"); // 调用接口(实现类)
		Map<String,String> partyinfomation = userOperationService.vilidateUser(map);
		String msgJson = "";
		if(partyinfomation==null){
			msgJson = JsonGenerateUtil.getCommonJson("error","请检查邮箱或用户名是否正确","","");
		}else{
			msgJson = JsonGenerateUtil.getCommonJson("success","登录成功成功","",partyinfomation);
		}
		HttpServletResponse response = this.getResponseHelper().getResponse();
		return new JsonResponse().responseJson(response, msgJson); // 返回 Json格式:
	}
	/**
	 * 验证会员是否已经存在
	 * @param email/partyname/mobilenumber
	 */
	@POST
	public String isOrNotExist(){
		Map<String, String> map = SerfjUtil.removeFilter(this.getParams());
		UserOperationService userOperationService = (UserOperationService) SofaSpringContext
				.getBean("userOperationService"); // 调用接口(实现类)
		Map<String,String> isornotexist = userOperationService.isOrNotExist(map);
		String msgJson = "";
		msgJson = JsonGenerateUtil.getCommonJson("success","查询成功，请根据值判断","",isornotexist);
		HttpServletResponse response = this.getResponseHelper().getResponse();
		return new JsonResponse().responseJson(response, msgJson); // 返回 Json格式:
	}
}

